﻿@using System.Collections.Generic
@model contos.Models.Instructor

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Instructor</legend>

        @Html.HiddenFor(model => model.InstructorID)

        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FirstMidName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstMidName)
            @Html.ValidationMessageFor(model => model.FirstMidName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.HireDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.HireDate)
            @Html.ValidationMessageFor(model => model.HireDate)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model=>model.OfficeAssignment.Location)
        </div>
        <div class="editor=field">
            @Html.EditorFor(model=>model.OfficeAssignment.Location)
            @Html.ValidationMessageFor(model=>model.OfficeAssignment.Location) 
        </div>
        <div class="editor-field"></div>
        <table>
            <tr>
                @{
                    int cnt = 0;
                    List<contos.ViewModel.AssignedCourseData> course = ViewBag.Courses;
                    foreach (var courseData in course)
                    {
                        if (cnt++%3 == 0)
                        {
                            @:</tr><tr>
                        }
                        @:<td>
                        <input type="checkbox"
                               name="selectedCourses" 
                               value="@courseData.CourseID"
                            @Html.Raw(courseData.Assigned ? "checked=\"checked\"" : "")/>
                            @courseData.CourseID  @:   @courseData.Title
                               
                        @:</td>
                    }
                    @: </tr>
                }
           
        </table>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
